package com.linq.cool.api.domain;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.linq.cool.common.core.domain.BaseEntity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.util.Date;

/**
 * @Author: yqlin
 * @Date: 2020/12/29 19:19
 * @Description: 用户信息表
 * @Version: 1.0.0
 */
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
@AllArgsConstructor
@Data
@Accessors(chain = true)
@TableName(value = "sys_user")
public class SysUser extends BaseEntity {

    private static final long serialVersionUID = 136548812234948208L;

    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    /**
     * 部门ID
     */
    @TableField(value = "dept_id")
    private Long deptId;

    /**
     * 用户账号
     */
    @TableField(value = "username")
    private String username;

    /**
     * 密码
     */
    @TableField(value = "`password`")
    private String password;

    /**
     * 用户邮箱
     */
    @TableField(value = "email")
    private String email;

    /**
     * 手机号码
     */
    @TableField(value = "phone")
    private String phone;

    /**
     * 用户性别（0:男 1:女 2:未知）
     */
    @TableField(value = "gender")
    private Integer gender;

    /**
     * 头像地址
     */
    @TableField(value = "avatar")
    private String avatar;

    /**
     * 帐号状态（0:正常 1:停用）
     */
    @TableField(value = "`status`")
    private Integer status;

    /**
     * 用户昵称
     */
    @TableField(value = "nickname")
    private String nickname;

    /**
     * 用户类型（0:系统用户 1: 其他用户）
     */
    @TableField(value = "`type`")
    private Integer type;

    /**
     * 删除标志（0:存在 1:删除）
     */
    @TableLogic
    @TableField(value = "is_deleted")
    private Integer isDeleted;

    /**
     * 最后登录IP
     */
    @TableField(value = "last_login_ip")
    private String lastLoginIp;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @TableField(value = "last_login_time")
    private Date lastLoginTime;

    /**
     * 备注
     */
    @TableField(value = "remark")
    private String remark;


    public SysUser(Long userId) {
        this.id = userId;
    }

    /**
     * 判断是否是超级管理员  userId=1L ---> 超级管理员
     */
    public static boolean isAdmin(Long userId) {
        return userId != null && 1L == userId;
    }

    /**
     * 判断是否是超级管理员
     */
    public boolean isAdmin() {
        return isAdmin(this.id);
    }

}